package tech.aistar.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 本类用来演示: session作用域
 *
 * @author: success
 * @date: 2021/1/8 10:00 上午
 */
@Controller
public class SessionController {

    @GetMapping("/set")
    @ResponseBody
    public String set(HttpSession session){
        //将数据放入到session作用域中
        //key-value的形式来存储数据的,可以存储多个键值对
        session.setAttribute("uname","admin");

        return "ok-set";
    }

    @GetMapping("/get")
    @ResponseBody
    public String get(HttpSession session){
        //从session作用域中根据key来获取value
        String uname = (String) session.getAttribute("uname");
        System.out.println(uname+"====");
        return "ok-get";
    }

}
